﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Drawing;

namespace ControlExplorer.samples.LoadOnDemand
{
  public partial class Overview : SpreadDemoPage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (IsPostBack)
      {
        return;
      }

      FpSpread1.DataSource = GetOrders();

      InitSpread(FpSpread1);
      this.FpSpread1.UseClipboard = false;
    }

    private void InitSpread(FarPoint.Web.Spread.FpSpread spread)
    {
      FpSpread1.ActiveSheetView.PageSize = 200;
      FpSpread1.AllowLoadOnDemand = true;
      FpSpread1.LoadInitRowCount = 15;
      FpSpread1.LoadRowIncrement = 5;
      FpSpread1.ActiveSheetView.AllowPage = false;


      //FpSpread1.ScrollBarBaseColor = Color.LightSteelBlue;
      //FpSpread1.ActiveSheetView.HeaderGrayAreaColor = Color.LightSteelBlue;

      //FarPoint.Web.Spread.LabelCellType ch = new FarPoint.Web.Spread.LabelCellType();
      //ch.BackgroundImageUrl = "../images/greenbk.jpg";
      //FpSpread1.ActiveSheetView.ColumnHeader.DefaultStyle.CellType = ch;
      //FpSpread1.ActiveSheetView.ColumnHeader.DefaultStyle.ForeColor = Color.White;
      //FpSpread1.ActiveSheetView.ColumnHeader.DefaultStyle.Font.Name = "Verdana";


      //FpSpread1.ActiveSheetView.SheetCornerStyle.CellType = ch; 

    }

    protected void FpSpread1_SaveOrLoadSheetState(object sender, FarPoint.Web.Spread.SheetViewStateEventArgs e)
    {
      if (e.IsSave)
      {
        Session["sheet1"] = e.SheetView.SaveViewState();
      }
      else
      {
        e.SheetView.LoadViewState(Session["sheet1"]);
      }
      e.Handled = true;
    }

    public DataSet GetOrders()
    {
      string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Northwind.mdb;Persist Security Info=True";
      string sqlstr = "SELECT * FROM Orders";

      DataSet orders = new DataSet();
      using (OleDbConnection myconn = new OleDbConnection(constr))
      {
        OleDbDataAdapter sqlAdapter1 = new OleDbDataAdapter(sqlstr, myconn);
        sqlAdapter1.Fill(orders, "orders");
        orders.Tables[0].Columns[0].Caption = "订单号";
        orders.Tables[0].Columns[1].Caption = "客户ID";
        orders.Tables[0].Columns[2].Caption = "雇员ID";
        orders.Tables[0].Columns[3].Caption = "订单日期";
        orders.Tables[0].Columns[4].Caption = "商机日期";
        orders.Tables[0].Columns[5].Caption = "下单日期";
        orders.Tables[0].Columns[6].Caption = "装货经由";
        orders.Tables[0].Columns[7].Caption = "运费";
        orders.Tables[0].Columns[8].Caption = "船名";
        orders.Tables[0].Columns[9].Caption = "送货地址";
        orders.Tables[0].Columns[10].Caption = "送货城市";
        orders.Tables[0].Columns[11].Caption = "送货区域";
        orders.Tables[0].Columns[12].Caption = "送货邮编";
        orders.Tables[0].Columns[13].Caption = "送货国家";
      }

      return orders;
    }
  }
}